fn main() {
    test1_string();
    println!("--------------------------");
    test2_multi_variable();
    println!("--------------------------");
    test3_clone();
    println!("--------------------------");
    test4_ownership_function();
    println!("--------------------------");
    test5_return_tuple();
}

fn test1_string() {
    let mut s = String::from("hello");
    s.push_str(",world!");
    println!("{s}");
    {
        let str = String::from("hello");
        //str is enable
    }
    //str is not enable
}

fn test2_multi_variable() {
    let x = 5;
    let y = x;
    println!("x={x}");
    println!("y={y}");

    let s1 = String::from("hello");
    let s2 = s1;
    //println!("s1={s1}");//err
    println!("s2={s2}");
}

fn test3_clone() {
    let s1 = String::from("hello");
    let s2 = s1.clone();
    println!("s1={s1},s2={s2}");
}

fn test4_ownership_function() {
    let s = String::from("hello");
    takes_ownership(s);
    //println!("s:{s}");//err

    let x = 5;
    makes_copy(x);
    println!("{x}");

    let s = gives_ownership();
    println!("{s}");
}
fn takes_ownership(str: String) {
    println!("{str}");
}
fn makes_copy(num: i32) {
    println!("{num}");
}
fn gives_ownership() -> String {
    String::from("yours")
}
fn test5_return_tuple() {
    let s1 = String::from("hello");
    let (s2, len) = calculate_len(s1);
    println!("len of {s2} is {len}");
}
fn calculate_len(str: String) -> (String, usize) {
    let len = str.len();
    (str, len)
}
